<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of test_m
 *
 * @author Gidaff_01
 */
class Test_m extends Model{
    //put your code here
    function Test_m(){
        parent::Model();
        $this->load->database();
    }

    function get_all_test($per_page, $offset){
        $this->db->select('
            lehu_profiles.display_name,
            zoo_produit.nomfr,
            zoo_test.id,
            zoo_test.livre,
            zoo_test.product_id,
            zoo_test.user_id
        ');
        $this->db->from('lehu_profiles ,zoo_test ,zoo_produit');
        $this->db->where('lehu_profiles.user_id = zoo_test.user_id');
        $this->db->where('zoo_test.product_id = zoo_produit.id');
        $this->db->order_by('zoo_test.id', 'DESC');
        $this->db->limit($per_page, $offset);
        $query = $this->db->get();
        return $query->result_array();
    }

    function count_all_test(){
         $this->db->select('
            lehu_profiles.display_name,
            zoo_produit.nomfr,
            zoo_test.id,
            zoo_test.livre,
            zoo_test.product_id,
            zoo_test.user_id
        ');
        $this->db->from('lehu_profiles ,zoo_test ,zoo_produit');
        $this->db->where('lehu_profiles.user_id = zoo_test.user_id');
        $this->db->where('zoo_test.product_id = zoo_produit.id');
        $this->db->order_by('zoo_test.id', 'DESC');
        $query = $this->db->get();
        return count($query->result_array());
    }

    function get_test_detail($id){
        $this->db->select('
            lehu_profiles.user_id,
            lehu_profiles.display_name,
            lehu_profiles.last_name,
            lehu_profiles.first_name,
            lehu_profiles.company,
            lehu_profiles.dob,
            lehu_profiles.gender,
            lehu_profiles.phone,
            lehu_profiles.mobile,
            lehu_profiles.address,
            lehu_profiles.gravatar,
            zoo_produit.nomfr,
            zoo_produit.prix,
            zoo_test.livre,
            zoo_produit.img,
            zoo_produit.descriptionfr,
            zoo_categories.nomfr as nom,
            zoo_test.id,
            lehu_users.email
        ');
        $this->db->from('lehu_profiles,lehu_users ,zoo_test,zoo_produit,zoo_categories');
        $this->db->where('lehu_profiles.user_id = zoo_test.user_id');
        $this->db->where('lehu_profiles.user_id = lehu_users.id');
        $this->db->where('zoo_test.product_id = zoo_produit.id');
        $this->db->where('zoo_categories.id = zoo_produit.catid');
        $this->db->where('zoo_test.id',$id);
        $this->db->order_by('zoo_test.id', 'DESC');
        $query = $this->db->get();
        return $query;
    }

    function delete_test($id){
        return $this->db->delete('zoo_test',array('id'=>$id));
    }

    function delivered($test_id){
        return $this->db->update('zoo_test',array('livre'=>1),array('id'=>$test_id));
    }
}
?>
